//
//  CXHAppDelegate.m
//  CXHAdSDK-UBiMAX
//
//  Created by 二跳 on 07/27/2025.
//  Copyright (c) 2025 二跳. All rights reserved.
//

#import "CXHAppDelegate.h"
#import <UBiMAXAdSDK/UMTAdSDK.h>
#import <UBiMAXSplash/UBiMAXSplash-umbrella.h>

@interface CXHAppDelegate ()<UMTSplashDelegate>

@property(nonatomic, strong) UMTSplash *splashAd;

@end

@implementation CXHAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    
    UMTAdSDKConfiguration *config = [[UMTAdSDKConfiguration alloc] init];
    config.appID = @"516881346296";
    config.debugLogEnabled = YES;
//    config.debugLogEnabled = YES;
    // 允许UBiMAX对于获取⽹络状态
    config.canReadNetType = YES;
    // 允许UBiMAX对于IDFA的获取
    config.canReadIDFA = NO;
    // 允许UBiMAX对于定位信息的获取
    config.locationEnabled = NO;
    // 同步初始化SDK
    [UMTAdSDKManager startSyncWithConfig:config completionHandler:^(BOOL succ, NSError *err) {
        if (succ) {
//            [self loadSplash];
            // 初始化成功，处理广告请求
        }else{
          //初始化失败
        }
    }];
    return YES;
}

- (void)loadSplash{
    UMTSplash *splash = [[UMTSplash alloc] initWithSlotId:@"1001068"];
    self.splashAd = splash;
    [[UMTAdManager sharedManager] loadSplashAd:splash extra:@{} delegate:self];
}

/// 开屏广告加载成功
- (void)umtSplashAd:(UMTSplash *)splash didLoadSuccWithExt:(NSDictionary *)ext {
    NSLog(@"%s", __func__);
  if ([[UMTAdManager sharedManager] isReadyForSplash:splash]) {
      [[UMTAdManager sharedManager] showSplash:splash
                                        window:self.window
                                          delegate:self];
      }
}
/// 开屏广告加载失败
- (void)umtSplashAd:(UMTSplash *)splash didLoadFailed:(UMTError *)error{
    NSLog(@"%s==%@", __func__,error.localizedDescription);
}


/// 开屏广告展示成功
- (void)umtSplashAd:(UMTSplash *)splash didShowSuccWithExt:(NSDictionary *)ext{
    NSLog(@"%s", __func__);
}
/// 开屏广告展示失败
- (void)umtSplashAd:(UMTSplash *)splash didShowFailed:(UMTError *)error{
    NSLog(@"%s", __func__);
}
/// 开屏广告点击
- (void)umtSplashAd:(UMTSplash *)splash didClickWithExt:(NSDictionary *)ext{
    NSLog(@"%s", __func__);
}
/// 开屏广告即将关闭
/// 目前仅支持 adx gdt
- (void)umtSplashAd:(UMTSplash *)splash willCloseWithExt:(NSDictionary *)ext{
    NSLog(@"%s", __func__);
}
/// 开屏广告关闭
- (void)umtSplashAd:(UMTSplash *)splash didCloseWithExt:(NSDictionary *)ext{
    NSLog(@"%s", __func__);
}

/// 开屏广告跳转详情页回调
/// 目前仅支持  gdt ks
- (void)umtSplashAd:(UMTSplash *)splash willPresentDetailWithExt:(NSDictionary *)ext{
    NSLog(@"%s", __func__);
}
/// 开屏广告关闭详情页回调
- (void)umtSplashAd:(UMTSplash *)splash didDetailCloseWithExt:(NSDictionary *)ext{
    NSLog(@"%s", __func__);
}

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
